//
//  ProjectStatisticsViewController.m
//  MyProject
//
//  Created by Pei on 16/8/4.
//  Copyright © 2016年 Xiaobo Pei. All rights reserved.
//

#import "ProjectStatisticsViewController.h"
#import "HTHorizontalSelectionList.h"
#import "IHRefreshTableView.h"
#import "StatisticsCell.h"
#import "ReportFormsViewController.h"
#import "ListViewController.h"
//#import "SelectCompanyViewController.h"
#import "SelectPersonViewController.h"
#import "SelectProjectViewController.h"
#import "UserInfo.h"

@interface ProjectStatisticsViewController ()<HTHorizontalSelectionListDelegate, HTHorizontalSelectionListDataSource,UITableViewDataSource,UITableViewDelegate,IHTableViewRefreshingDelegate,ListViewControllerDelegate,SelectProjectViewControllerDelegate, SelectPersonViewControllerDelegate>
{
    HTHorizontalSelectionList *_segementView;
    NSArray *_titleArray;
    
    UIView *_bottomView;
    
    IHRefreshTableView *_myTable;
    
    UIView *_headerView;
    
    NSString *typeStr;
    
    ListViewController *listVC;
    
    UIDatePicker *_datePicker;
    UIView *_dateTopView;
    
    UILabel *beginLbl;
    UILabel *endLbl;
    
    NSString *beginStr;
    NSString *endStr;
    
    NSString *passType;
    
    NSString *_currentStr;
    
    NSMutableString *companyStr;
    
    UILabel *companyLbl;
    UILabel *personLbl;
    
    NSArray *companyArray;
    
    //NSArray *personArray;
    NSDictionary *personDic;
    
    NSArray *projectArray;
    NSDictionary *projectDic;
    
    NSDictionary *dataDic;
    
    UIButton *rightBtn;
}

@end

@implementation ProjectStatisticsViewController

- (id)initWithType:(NSString*)type
{
    self = [super init];
    if (self) {
        passType = type;
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    [[NSNotificationCenter defaultCenter] postNotificationName:Hide_TabBar_Notification object:nil];
}


- (void)viewDidLoad {
    
    //self.navTitle = @"统计";
    
    [super viewDidLoad];
    
    companyStr = [[NSMutableString alloc] initWithCapacity:3];
    
    rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 70, 22)];
    [rightBtn setTitle:@"报表模式" forState:UIControlStateNormal];
    [rightBtn setTitleColor:kBlueColor forState:UIControlStateNormal];
    rightBtn.titleLabel.font = kAppFont(Home_Big_Size);
    [rightBtn addTarget:self action:@selector(rightBtnAcion) forControlEvents:UIControlEventTouchUpInside];
    //[self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:rightBtn]];
    
    _titleArray = @[@"隐患类别", @"检查类别", @"隐患类别", @"合格率"];
    
    typeStr = @"0";
    
    [self initSelectView];
    [self initTopBottomView];
    [self initTableView];
    //[self initTableHeaderView];
    
    
    
//    NSArray *InspectTypeArray = [[NSUserDefaults standardUserDefaults] objectForKey:Check_Type_Items];
//    if (InspectTypeArray != nil && InspectTypeArray.count > 0) {
//    }else{
        [self getInspectTypeData];
//    }
    
    
}

- (void)getRiskLevelData{
    [[YMNetLib getInstance] connectWithAction:Dictionary_Type_API method:@"GET" withContent:@"DicType=RiskLevel" withBody:nil withDelegate:self];
    _currentStr = @"Dic_RiskLevel";
}

- (void)getRiskTypeData{
    [[YMNetLib getInstance] connectWithAction:Dictionary_Type_API method:@"GET" withContent:@"DicType=RiskType" withBody:nil withDelegate:self];
    _currentStr = @"Dic_RiskType";
}

- (void)getInspectTypeData
{
    [[YMNetLib getInstance] connectWithAction:Dictionary_Type_API method:@"GET" withContent:[NSString stringWithFormat:@"DicType=%@", @"InspectType"] withBody:nil withDelegate:self];
    _currentStr = @"Dic_InspectType";
}

- (void)getData
{
    
    NSMutableArray *aaaa = [[NSMutableArray alloc] initWithCapacity:3];
    [aaaa removeAllObjects];
    for (NSDictionary *dddd in projectArray) {
        [aaaa addObject:[dddd valueForKey:@"ProjectCode"]];
    }
    
    if (aaaa == nil || aaaa.count <= 0) {
        [[YMUIUtil getInstance] showTipViewAutoDis:@"检查项目不能为空"];
        return;
    }
    
    if (endStr != nil && endStr.length > 0 && beginStr != nil && beginStr.length > 0) {
        int ttt = [self compareOneDay:[self dateFromString:endStr] withAnotherDay:[self dateFromString:beginStr]];
        if (ttt < 1) {
            [[YMUIUtil getInstance] showTipViewAutoDis:@"开始时间不能大于结束时间"];
            return;
        }
    }
    
    //    if (beginStr == nil || beginStr.length <= 0) {
    //        [[YMUIUtil getInstance] showTipViewAutoDis:@"开始时间不能为空"];
    //        return;
    //
    //    }
    //
    //    if (endStr == nil || endStr.length <= 0) {
    //        [[YMUIUtil getInstance] showTipViewAutoDis:@"结束时间不能为空"];
    //        return;
    //
    //    }
    
//    NSString *ssss = [projectDic valueForKey:@"ParentOrgCode"];
//    NSString *InspectOrgCodeStr = @"";
//    if (ssss != nil && ssss.length > 0) {
//        InspectOrgCodeStr = ssss;
//    }
//    
//    NSMutableArray *rrrr = [[NSMutableArray alloc] initWithCapacity:3];
//    [rrrr removeAllObjects];
//    if (projectArray != nil && projectArray.count > 0) {
//        for (NSDictionary *dddd in projectArray) {
//            [rrrr addObject:[dddd valueForKey:@"UserID"]];
//        }
//    }
    
    if (beginStr ==  nil || beginStr.length <= 0) {
        beginStr = @"";
    }
    if (endStr ==  nil || endStr.length <= 0) {
        endStr = @"";
    }

    
    //Get_Statistics_Company
    NSDictionary *bodyDic = [NSDictionary dictionaryWithObjectsAndKeys:
                             [[UserInfo getInstance] getUserID],@"UserID",
                             aaaa,@"ProjectCodeList",
                             passType, @"Level",//0:公司,1项目
                             typeStr, @"Type",
                             beginStr, @"InspectBeginDate",
                             endStr, @"InspectEndDate",
                             [projectDic valueForKey:@"UserID"],@"InspectUserID",
                             
                             nil];
    [[YMNetLib getInstance] connectWithAction:Get_Statistics_Company method:@"POST" withContent:nil withBody:bodyDic withDelegate:self];
    _currentStr = Get_Statistics_Company;
}


- (void)NetDoOverSuccess:(NSDictionary*)body
{
    if ([_currentStr isEqualToString:Get_Statistics_Company]) {
        dataDic = body;
        
        NSArray *dataList = [dataDic objectForKey:@"DataList"];
        
        if (dataList != nil || dataList.count > 0) {
            [self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:rightBtn]];
        }

        
        [listVC loadData:body type:[typeStr intValue] leverl:[passType intValue]];
        [listVC.tableView reloadData];
    }else if([_currentStr isEqualToString:@"Dic_InspectType"]){
        if ([[YMNetDataUtil getSuccessState:body] intValue] == 1) {
            [[NSUserDefaults standardUserDefaults] setObject:[body valueForKey:@"DicList"] forKey:Check_Type_Items];
            
//            NSArray *RiskLevelArray = [[NSUserDefaults standardUserDefaults] objectForKey:select_RiskLevel];
//            if (RiskLevelArray != nil && RiskLevelArray.count > 0) {
//            }else{
                [self getRiskLevelData];
//            }

        }
    }else if ([_currentStr isEqualToString:@"Dic_RiskLevel"]){
        if ([[YMNetDataUtil getSuccessState:body] intValue] == 1) {
            [[NSUserDefaults standardUserDefaults] setObject:[body valueForKey:@"DicList"] forKey:select_RiskLevel];
            
//            NSArray *tempArray = [[NSUserDefaults standardUserDefaults] objectForKey:Dic_RiskType];
//            if (tempArray != nil && tempArray.count > 0) {
//            }else{
                [self getRiskTypeData];
//            }

        }
    }
    else{
        if ([[YMNetDataUtil getSuccessState:body] intValue] == 1) {
            [[NSUserDefaults standardUserDefaults] setObject:[body valueForKey:@"DicList"] forKey:Dic_RiskType];
        }
    }
    
}

-(int)compareOneDay:(NSDate *)oneDay withAnotherDay:(NSDate *)anotherDay
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString *oneDayStr = [dateFormatter stringFromDate:oneDay];
    NSString *anotherDayStr = [dateFormatter stringFromDate:anotherDay];
    NSDate *dateA = [dateFormatter dateFromString:oneDayStr];
    NSDate *dateB = [dateFormatter dateFromString:anotherDayStr];
    NSComparisonResult result = [dateA compare:dateB];
    NSLog(@"date1 : %@, date2 : %@", oneDay, anotherDay);
    if (result == NSOrderedDescending) {
        //NSLog(@"Date1  is in the future");
        return 1;
    }
    else if (result == NSOrderedAscending){
        //NSLog(@"Date1 is in the past");
        return -1;
    }
    //NSLog(@"Both dates are the same");
    return 0;
    
}

- (NSDate *)dateFromString:(NSString *)dateString{
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat: @"yyyy-MM-dd"];
    NSDate *destDate= [dateFormatter dateFromString:dateString];
    return destDate;
    
}

#pragma mark **************************** UI *******************************
- (void)initSelectView
{
    _segementView = [[HTHorizontalSelectionList alloc] initWithFrame:CGRectMake(0.0f, 0.0f, kDeviceWidth, 40.0f)];
    _segementView.delegate = self;
    _segementView.dataSource = self;
    _segementView.autoFillWidth = YES;
    _segementView.font = (Home_Small_Size+2);
    _segementView.sideMargin = 0;
    _segementView.isAdjustBottomLine = YES;
    _segementView.bottomLineMargin = 10.f;
    _segementView.selectionIndicatorColor = kBlueColor;
    [_segementView setSelectedButtonIndex:0];
    [_segementView setTitleColor:kGreenColor forState:UIControlStateNormal];
    [_segementView setBottomTrimColor:kGreenColor];
    [self.view addSubview:_segementView];
}

- (void)initTopBottomView
{
    _bottomView = [[UIView alloc] init];
    _bottomView.frame = CGRectMake(0.0f, _segementView.bottom, kDeviceWidth, 40.0f*3.0f+60.0f);
    _bottomView.backgroundColor = kWhiteColor;
    [self.view addSubview:_bottomView];
    
    UIControl *companyControl = [[UIControl alloc] init];
    companyControl.frame = CGRectMake(0.0f, 0.0f, kDeviceWidth, 40.0f);
    [companyControl addTarget:self action:@selector(companyControlAction) forControlEvents:UIControlEventTouchUpInside];
    [_bottomView addSubview:companyControl];
    
    companyLbl = [[UILabel alloc] init];
    companyLbl.frame = CGRectMake(10.0f, (40-(Home_Small_Size+2.0f))/2.0f, kDeviceWidth-10.0f*2.0f-10.0f, Home_Small_Size+2.0f);
    companyLbl.font = kAppFont(Home_Small_Size+2.0f);
    companyLbl.text = @"项目选择";
    companyLbl.textColor = kGreenColor;
    [companyControl addSubview:companyLbl];
    
    UIImageView *companyArrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"06jiantou-"]];
    companyArrowImageView.frame = CGRectMake(kDeviceWidth-10.0f/2.0f-10.0f,(40-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
    [companyControl addSubview:companyArrowImageView];
    
    UIView *companyLineView = [[UIView alloc] init];
    companyLineView.frame = CGRectMake(10.0f, 40.0f-0.5f, kDeviceWidth-10*2, 0.5f);
    companyLineView.backgroundColor = kGreenColor;
    [companyControl addSubview:companyLineView];
    
    /*
     UIControl *departmentControl = [[UIControl alloc] init];
     departmentControl.frame = CGRectMake(0.0f, companyControl.bottom, kDeviceWidth/2.0f, 40.0f);
     [departmentControl addTarget:self action:@selector(departmentControlAction) forControlEvents:UIControlEventTouchUpInside];
     [_bottomView addSubview:departmentControl];
     
     UILabel *departmentLbl = [[UILabel alloc] init];
     departmentLbl.frame = CGRectMake(10.0f, (40-(Home_Small_Size+2.0f))/2.0f, 80.0f, Home_Small_Size+2.0f);
     departmentLbl.font = kAppFont(Home_Small_Size+2.0f);
     departmentLbl.text = @"检查部门";
     departmentLbl.textColor = kGreenColor;
     [departmentControl addSubview:departmentLbl];
     
     UIImageView *departmentArrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"06jiantou-"]];
     departmentArrowImageView.frame = CGRectMake(kDeviceWidth/2.0f-10.0f/2.0f-10.0f,(40-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
     [departmentControl addSubview:departmentArrowImageView];
     
     UIView *departmentLineView = [[UIView alloc] init];
     departmentLineView.frame = CGRectMake(10.0f, 40.0f-0.5f, kDeviceWidth/2.0f-10, 0.5f);
     departmentLineView.backgroundColor = kGreenColor;
     [departmentControl addSubview:departmentLineView];
     */
    
    UIControl *personControl = [[UIControl alloc] init];
    personControl.frame = CGRectMake(0.0f, companyControl.bottom, kDeviceWidth, 40.0f);
    [personControl addTarget:self action:@selector(personControlAction) forControlEvents:UIControlEventTouchUpInside];
    [_bottomView addSubview:personControl];
    
    
    personLbl = [[UILabel alloc] init];
    personLbl.frame = CGRectMake(10.0f, (40-(Home_Small_Size+2.0f))/2.0f, kDeviceWidth-10.0f*2.0f-10.0f, Home_Small_Size+2.0f);
    personLbl.font = kAppFont(Home_Small_Size+2.0f);
    personLbl.text = @"检查人";
    personLbl.textColor = kGreenColor;
    [personControl addSubview:personLbl];
    
    UIImageView *personArrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"06jiantou-"]];
    personArrowImageView.frame = CGRectMake(kDeviceWidth-10.0f/2.0f-10.0f,(40-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
    [personControl addSubview:personArrowImageView];
    
    UIView *personLineView = [[UIView alloc] init];
    personLineView.frame = CGRectMake(10.0f, 40.0f-0.3f, kDeviceWidth-10*2.0f, 0.3f);
    personLineView.backgroundColor = kGreenColor;
    [personControl addSubview:personLineView];
    
    
    
    UIControl *beginControl = [[UIControl alloc] init];
    beginControl.frame = CGRectMake(0.0f, personControl.bottom, kDeviceWidth/2.0f, 40.0f);
    [beginControl addTarget:self action:@selector(beginControlAction) forControlEvents:UIControlEventTouchUpInside];
    [_bottomView addSubview:beginControl];
    
    
    beginLbl = [[UILabel alloc] init];
    beginLbl.frame = CGRectMake(10.0f, (40-(Home_Small_Size+2.0f))/2.0f, beginControl.width-10.0f/2.0f-2.0f, Home_Small_Size+2.0f);
    beginLbl.font = kAppFont(Home_Small_Size+2.0f);
    beginLbl.text = @"开始日期";
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    // 格式化日期格式
    formatter. dateFormat = @"yyyy-MM-dd";
    NSDate *afterDate = [NSDate dateWithTimeIntervalSinceNow:-180*24*60*60];
    NSString *dateStr = [formatter stringFromDate:afterDate];
    beginStr = dateStr;
    
    beginLbl.text = beginStr;

    
    beginLbl.textColor = kGreenColor;
    [beginControl addSubview:beginLbl];
    
    UIImageView *beginArrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"06jiantou-"]];
    beginArrowImageView.frame = CGRectMake(kDeviceWidth/2.0f-10.0f/2.0f-2.0f,(40-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
    [beginControl addSubview:beginArrowImageView];
    
    UIView *beginLineView = [[UIView alloc] init];
    beginLineView.frame = CGRectMake(10.0f, 40.0f-0.5f, kDeviceWidth/2.0f-10, 0.5f);
    beginLineView.backgroundColor = kGreenColor;
    [beginControl addSubview:beginLineView];
    
    
    UIControl *endControl = [[UIControl alloc] init];
    endControl.frame = CGRectMake(kDeviceWidth/2.0f, personControl.bottom, kDeviceWidth/2.0f, 40.0f);
    [endControl addTarget:self action:@selector(endControlAction) forControlEvents:UIControlEventTouchUpInside];
    [_bottomView addSubview:endControl];
    
    
    endLbl = [[UILabel alloc] init];
    endLbl.frame = CGRectMake(10.0f, (40-(Home_Small_Size+2.0f))/2.0f, endControl.width-10.0f/2.0f-2.0f, Home_Small_Size+2.0f);
    endLbl.font = kAppFont(Home_Small_Size+2.0f);
    endLbl.text = @"结束日期";
    
    NSDateFormatter *endFormatter = [[NSDateFormatter alloc] init];
    // 格式化日期格式
    endFormatter. dateFormat = @"yyyy-MM-dd";
    NSDate *endAfterDate = [NSDate dateWithTimeIntervalSinceNow:0];
    NSString *endDateStr = [formatter stringFromDate:endAfterDate];
    endStr = endDateStr;
    
    endLbl.text = endStr;

    
    endLbl.textColor = kGreenColor;
    [endControl addSubview:endLbl];
    
    UIImageView *endArrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"06jiantou-"]];
    endArrowImageView.frame = CGRectMake(kDeviceWidth/2.0f-10.0f/2.0f-2.0f,(40-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
    [endControl addSubview:endArrowImageView];
    
    UIView *endLineView = [[UIView alloc] init];
    endLineView.frame = CGRectMake(0.0f, 40.0f-0.5f, kDeviceWidth/2.0f-10, 0.5f);
    endLineView.backgroundColor = kGreenColor;
    [endControl addSubview:endLineView];
    
    UIButton *queryBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    queryBtn.frame = CGRectMake(30.0f, endControl.bottom+10.0f, (kDeviceWidth-30.0f*3.0f)/2.0f, 40.0f);
    [queryBtn setBackgroundColor:kRedColor];
    [queryBtn setTitle:@"查询" forState:UIControlStateNormal];
    queryBtn.layer.masksToBounds = YES;
    queryBtn.layer.cornerRadius = 4.0f;
    [queryBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
    [queryBtn addTarget:self action:@selector(queryBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [_bottomView addSubview:queryBtn];
    
    UIButton *cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cancleBtn.frame = CGRectMake(queryBtn.right+30.0f, endControl.bottom+10.0f, (kDeviceWidth-30.0f*3.0f)/2.0f, 40.0f);
    [cancleBtn setBackgroundColor:kRedColor];
    [cancleBtn setTitle:@"重置" forState:UIControlStateNormal];
    cancleBtn.layer.masksToBounds = YES;
    cancleBtn.layer.cornerRadius = 4.0f;
    [cancleBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
    [cancleBtn addTarget:self action:@selector(cancleBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [_bottomView addSubview:cancleBtn];
}

- (void)initTableView
{
    /*
     CGRect frame = CGRectMake(0, _bottomView.bottom+10.0f, kDeviceWidth, kDeviceHeight-NAV_HEIGHT-_bottomView.height-10.0f);
     _myTable = [[IHRefreshTableView alloc] initWithFrame:frame refreshType:-1 andAutoLoad:NO];
     _myTable.delegate = self;
     _myTable.dataSource = self;
     _myTable.refreshDelegate = self;
     _myTable.footer.hidden = YES;
     _myTable.header.hidden = YES;
     //[self.view addSubview:_myTable];
     */
    
    listVC = [[ListViewController alloc] init];
    listVC.view.frame = CGRectMake(0, _bottomView.bottom+10.0f, kDeviceWidth, self.view.height-_bottomView.bottom-10.0f-1.0f);
    listVC.delegate = self;
    [self.view addSubview:listVC.view];
}

- (void)passReload
{
    [listVC.tableView reloadData];
}

- (void)initTableHeaderView
{
    _headerView = [[UIView alloc] init];
    _headerView.frame = CGRectMake(0.0f, 0.0f, kDeviceWidth, 50.0f);
    _headerView.backgroundColor = kWhiteColor;
    _myTable.tableHeaderView = _headerView;
    
    UILabel *lbl1 = [[UILabel alloc] init];
    lbl1.frame = CGRectMake(0.0f, (50-(Home_Small_Size+2.0f))/2.0f, kDeviceWidth/3.0f, Home_Small_Size+2.0f);
    lbl1.font = kAppFont(Home_Small_Size+2.0f);
    lbl1.text = @"问题数量：6";
    lbl1.textAlignment = NSTextAlignmentCenter;
    lbl1.textColor = kGreenColor;
    [_headerView addSubview:lbl1];
    
    UILabel *lbl2 = [[UILabel alloc] init];
    lbl2.frame = CGRectMake(kDeviceWidth/3.0f, (50-(Home_Small_Size+2.0f))/2.0f, kDeviceWidth/3.0f, Home_Small_Size+2.0f);
    lbl2.font = kAppFont(Home_Small_Size+2.0f);
    lbl2.text = @"文明用电：6";
    lbl2.textAlignment = NSTextAlignmentCenter;
    lbl2.textColor = kGreenColor;
    [_headerView addSubview:lbl2];
    
    UILabel *lbl3 = [[UILabel alloc] init];
    lbl3.frame = CGRectMake(kDeviceWidth/3.0f*2.0f, (50-(Home_Small_Size+2.0f))/2.0f, kDeviceWidth/3.0f, Home_Small_Size+2.0f);
    lbl3.font = kAppFont(Home_Small_Size+2.0f);
    lbl3.text = @"管理：6";
    lbl3.textAlignment = NSTextAlignmentCenter;
    lbl3.textColor = kGreenColor;
    [_headerView addSubview:lbl3];
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(10.0f, 50.0f-0.5f, kDeviceWidth-10*2, 0.5f)];
    lineView.backgroundColor = kGreenColor;
    [_headerView addSubview:lineView];
    
}

#pragma mark **************************** Action *********************************
- (void)sureBtnAcion:(UIButton*)sender
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    // 格式化日期格式
    formatter. dateFormat = @"yyyy-MM-dd";
    NSString *dateStr = [formatter stringFromDate:_datePicker.date];
    NSLog(@"=====%@", dateStr);
    
    switch (sender.tag)
    {
        case 119:
        {
            beginLbl.text = [NSString stringWithFormat:@"开始日期:%@",dateStr];
            beginStr = dateStr;
        }
            break;
        case 116:
        {
            endLbl.text = [NSString stringWithFormat:@"结束日期:%@",dateStr];
            endStr = dateStr;
        }
            break;
        default:
            break;
    }
    
    
    
    [_datePicker removeFromSuperview];
    _datePicker = nil;
    [_dateTopView removeFromSuperview];
    _dateTopView = nil;
    
}

- (void)cancleBtnAcion:(UIButton*)sender
{
    [_datePicker removeFromSuperview];
    _datePicker = nil;
    [_dateTopView removeFromSuperview];
    _dateTopView = nil;
}

- (void)companyControlAction
{
    SelectProjectViewController *companyVC = [[SelectProjectViewController alloc] init];
    companyVC.delegate = self;
    [self.navigationController pushViewController:companyVC animated:YES];
}

- (void)passProjectData:(NSArray *)data super:(NSDictionary *)dic{
    projectArray = data;
    projectDic = dic;
    
    NSMutableString *rrrr = [[NSMutableString alloc] initWithCapacity:3];
    [rrrr setString:@""];
    if (projectArray != nil && projectArray.count > 0) {
        for (NSDictionary *dddd in projectArray) {
            [rrrr appendString:[NSString stringWithFormat:@"%@ ",[dddd valueForKey:@"ProjectName"]]];
        }
    }
    companyLbl.text = [NSString stringWithFormat:@"项目选择:%@", rrrr];//@"项目选择";
    //personLbl.text = [NSString stringWithFormat:@"检查人:%@", rrrr];
}

//- (void)passProjectData:(NSArray *)data{
//    companyArray = data;
//    [companyStr setString:@""];
//    for (NSDictionary *dddd in data) {
//        [companyStr appendString:[NSString stringWithFormat:@"%@ ", [dddd valueForKey:@"OrgName"]]];
//    }
//    
//    companyLbl.text = [NSString stringWithFormat:@"项目选择:%@", companyStr];//@"项目选择";
//}


- (void)departmentControlAction
{
    
}

- (void)personControlAction
{
    SelectPersonViewController *personVC = [[SelectPersonViewController alloc] init];
    personVC.delegate = self;
    [self.navigationController pushViewController:personVC animated:YES];
}

- (void)passPersonData:(NSDictionary *)data super:(NSDictionary *)dic{
    //personArray = data;
    personDic = data;
    
//    NSMutableString *rrrr = [[NSMutableString alloc] initWithCapacity:3];
//    [rrrr setString:@""];
//    if (personArray != nil && personArray.count > 0) {
//        for (NSDictionary *dddd in personArray) {
//            [rrrr appendString:[NSString stringWithFormat:@"%@ ",[dddd valueForKey:@"UserName"]]];
//        }
//    }
    personLbl.text = [NSString stringWithFormat:@"检查人:%@", [personDic valueForKey:@"UserName"]];
}

- (void)beginControlAction
{
    [_datePicker removeFromSuperview];
    _datePicker = nil;
    _datePicker = [[UIDatePicker alloc] init];
    _datePicker.datePickerMode = UIDatePickerModeDate;
    //_datePicker.minimumDate = [NSDate date];
    _datePicker.frame = CGRectMake(0.0f, self.view.height-200.0f, kDeviceWidth, 200.0f);
    _datePicker.backgroundColor = kDefaultBackgroundColor;
    [self.view addSubview:_datePicker];
    
    [_dateTopView removeFromSuperview];
    _dateTopView = nil;
    _dateTopView = [[UIView alloc] init];
    _dateTopView.backgroundColor = kWhiteColor;
    _dateTopView.frame = CGRectMake(-0.5f, self.view.height-_datePicker.height-40.0f, kDeviceWidth+1.0f, 40.0f);
    _dateTopView.layer.borderColor = kGreenColor.CGColor;
    _dateTopView.layer.borderWidth = 0.5f;
    [self.view addSubview:_dateTopView];
    
    UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [sureBtn setTitle:@"确认" forState:UIControlStateNormal];
    [sureBtn setTitleColor:kBlueColor forState:UIControlStateNormal];
    sureBtn.titleLabel.font = kAppFont(Home_Big_Size);
    sureBtn.frame = CGRectMake(kDeviceWidth-40.0f-16.0f, (40-Home_Big_Size)/2.0f, 40.0f, Home_Big_Size);
    [sureBtn addTarget:self action:@selector(sureBtnAcion:) forControlEvents:UIControlEventTouchUpInside];
    sureBtn.tag = 119;
    [_dateTopView addSubview:sureBtn];
    
    UIButton *cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [cancleBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancleBtn setTitleColor:kBlueColor forState:UIControlStateNormal];
    cancleBtn.titleLabel.font = kAppFont(Home_Big_Size);
    cancleBtn.frame = CGRectMake(16.0f, (40-Home_Big_Size)/2.0f, 40.0f, Home_Big_Size);
    [cancleBtn addTarget:self action:@selector(cancleBtnAcion:) forControlEvents:UIControlEventTouchUpInside];
    cancleBtn.tag = 119;
    [_dateTopView addSubview:cancleBtn];
    
}

- (void)endControlAction
{
    [_datePicker removeFromSuperview];
    _datePicker = nil;
    _datePicker = [[UIDatePicker alloc] init];
    _datePicker.datePickerMode = UIDatePickerModeDate;
    //_datePicker.minimumDate = [NSDate date];
    _datePicker.frame = CGRectMake(0.0f, self.view.height-200.0f, kDeviceWidth, 200.0f);
    _datePicker.backgroundColor = kDefaultBackgroundColor;
    [self.view addSubview:_datePicker];
    
    [_dateTopView removeFromSuperview];
    _dateTopView = nil;
    _dateTopView = [[UIView alloc] init];
    _dateTopView.backgroundColor = kWhiteColor;
    _dateTopView.frame = CGRectMake(-0.5f, self.view.height-_datePicker.height-40.0f, kDeviceWidth+1.0f, 40.0f);
    _dateTopView.layer.borderColor = kGreenColor.CGColor;
    _dateTopView.layer.borderWidth = 0.5f;
    [self.view addSubview:_dateTopView];
    
    UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [sureBtn setTitle:@"确认" forState:UIControlStateNormal];
    [sureBtn setTitleColor:kBlueColor forState:UIControlStateNormal];
    sureBtn.titleLabel.font = kAppFont(Home_Big_Size);
    sureBtn.frame = CGRectMake(kDeviceWidth-40.0f-16.0f, (40-Home_Big_Size)/2.0f, 40.0f, Home_Big_Size);
    [sureBtn addTarget:self action:@selector(sureBtnAcion:) forControlEvents:UIControlEventTouchUpInside];
    sureBtn.tag = 116;
    [_dateTopView addSubview:sureBtn];
    
    UIButton *cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [cancleBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancleBtn setTitleColor:kBlueColor forState:UIControlStateNormal];
    cancleBtn.titleLabel.font = kAppFont(Home_Big_Size);
    cancleBtn.frame = CGRectMake(16.0f, (40-Home_Big_Size)/2.0f, 40.0f, Home_Big_Size);
    [cancleBtn addTarget:self action:@selector(cancleBtnAcion:) forControlEvents:UIControlEventTouchUpInside];
    cancleBtn.tag = 116;
    [_dateTopView addSubview:cancleBtn];
}

- (void)queryBtnAction
{
    [self getData];
}

- (void)cancleBtnAction
{
    [_datePicker removeFromSuperview];
    _datePicker = nil;
    [_dateTopView removeFromSuperview];
    _dateTopView = nil;
    
    companyArray = nil;
    companyLbl.text = @"项目选择";//@"项目选择";
    
    projectArray = nil;
    projectDic = nil;
    personLbl.text = @"检查人";
    
    beginLbl.text = @"开始日期";
    endLbl.text = @"结束日期";

    beginStr = @"";
    endStr = @"";
}

- (void)rightBtnAcion
{
    ReportFormsViewController *horizontalVC = [[ReportFormsViewController alloc] initWithData:[dataDic objectForKey:@"DataList"] typeInt:[typeStr intValue] level:[passType intValue]];
    [self presentViewController:horizontalVC animated:YES completion:nil];
}

#pragma mark **************************** Delegate *******************************

#pragma mark - HTHorizontalSelectionList delegate
- (NSInteger)numberOfItemsInSelectionList:(HTHorizontalSelectionList *)selectionList
{
    return _titleArray.count;
}

- (NSString *)selectionList:(HTHorizontalSelectionList *)selectionList titleForItemWithIndex:(NSInteger)index
{
    return _titleArray[index];
}

- (void)selectionList:(HTHorizontalSelectionList *)selectionList didSelectButtonWithIndex:(NSInteger)index
{
    switch (index) {
        case 0:
        {
            typeStr = @"0";
        }
            break;
        case 1:
        {
            typeStr = @"1";
        }
            break;
        case 2:
        {
            typeStr = @"2";
        }
            break;
        case 3:
        {
            typeStr = @"3";
        }
            break;
        default:
            break;
    }
}




#pragma mark  ************************* UITableViewDataSource **************************************
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;//[_houseResouce count];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cell_house_History";
    StatisticsCell *cell = (StatisticsCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil)
    {
        cell = [[StatisticsCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.text = @"项目名称：xxxx";
    cell.textLabel.font = kAppFont(Home_Small_Size+2.0f);
    cell.textLabel.textColor = kBlackColor;
    
    cell.detailTextLabel.text = @"问题数量：6  文明用电：6   管理：6";
    cell.detailTextLabel.font = kAppFont(Home_Small_Size);
    cell.detailTextLabel.textColor = kGreenColor;
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}


#pragma mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}


@end
